﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="XsdMinOccursMaxOccursBuiltinTypes", Namespace="http://kis.x-road.eu/", Target=typeof(XsdMinOccursMaxOccursBuiltinTypes))]
    public class XsdMinOccursMaxOccursBuiltinTypesSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected XsdMinOccursMaxOccursBuiltinTypes clazz;
        
        public XsdMinOccursMaxOccursBuiltinTypesSerializer(XsdMinOccursMaxOccursBuiltinTypes clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.StringMin0Maz1NonNil!=null) {
                Writer.WriteStartElement("String_Min0_Maz_1_NonNil");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdToken(((string)(clazz.StringMin0Maz1NonNil))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.StringMin0Maz1Nil!=null) {
                Writer.WriteStartElement("String_Min0_Maz_1_Nil");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdToken(((string)(clazz.StringMin0Maz1Nil))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("String_Min1_Maz_1_NonNil");
            if (clazz.StringMin1Maz1NonNil!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdToken(((string)(clazz.StringMin1Maz1NonNil))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : StringMin1Maz1NonNil");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("String_Min1_Maz_1_Nil");
            if (clazz.StringMin1Maz1Nil!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdToken(((string)(clazz.StringMin1Maz1Nil))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            if (clazz.Min0Maz1NonNil!=null) {
                Writer.WriteStartElement("Min0_Maz_1_NonNil");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdUnsignedShort(((ushort)(clazz.Min0Maz1NonNil))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Min0Maz1Nil!=null) {
                Writer.WriteStartElement("Min0_Maz_1_Nil");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdUnsignedShort(((ushort)(clazz.Min0Maz1Nil))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("Min1_Maz_1_NonNil");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdUnsignedShort(((ushort)(clazz.Min1Maz1NonNil))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("Min1_Maz_1_Nil");
            if (clazz.Min1Maz1Nil!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdUnsignedShort(((ushort)(clazz.Min1Maz1Nil))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="String_Min0_Maz_1_NonNil") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdMinOccursMaxOccursBuiltinTypes>String_Min0_Maz_1_NonNil");
                }
                clazz.StringMin0Maz1NonNil = new global::Xtee.Core.Schema.XsdToken(Reader.ReadElementString("String_Min0_Maz_1_NonNil")).Value;
            }
            if (Reader.LocalName=="String_Min0_Maz_1_Nil") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.StringMin0Maz1Nil = new global::Xtee.Core.Schema.XsdToken(Reader.ReadElementString("String_Min0_Maz_1_Nil")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="String_Min1_Maz_1_NonNil") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdMinOccursMaxOccursBuiltinTypes>String_Min1_Maz_1_NonNil");
                }
                clazz.StringMin1Maz1NonNil = new global::Xtee.Core.Schema.XsdToken(Reader.ReadElementString("String_Min1_Maz_1_NonNil")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>XsdMinOccursMaxOccursBuiltinTypes>String_Min1_Maz_1_NonNil", Reader.LocalName);
            }
            if (Reader.LocalName=="String_Min1_Maz_1_Nil") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.StringMin1Maz1Nil = new global::Xtee.Core.Schema.XsdToken(Reader.ReadElementString("String_Min1_Maz_1_Nil")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>XsdMinOccursMaxOccursBuiltinTypes>String_Min1_Maz_1_Nil", Reader.LocalName);
            }
            if (Reader.LocalName=="Min0_Maz_1_NonNil") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdMinOccursMaxOccursBuiltinTypes>Min0_Maz_1_NonNil");
                }
                clazz.Min0Maz1NonNil = new global::Xtee.Core.Schema.XsdUnsignedShort(Reader.ReadElementString("Min0_Maz_1_NonNil")).Value;
            }
            if (Reader.LocalName=="Min0_Maz_1_Nil") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Min0Maz1Nil = new global::Xtee.Core.Schema.XsdUnsignedShort(Reader.ReadElementString("Min0_Maz_1_Nil")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Min1_Maz_1_NonNil") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdMinOccursMaxOccursBuiltinTypes>Min1_Maz_1_NonNil");
                }
                clazz.Min1Maz1NonNil = new global::Xtee.Core.Schema.XsdUnsignedShort(Reader.ReadElementString("Min1_Maz_1_NonNil")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>XsdMinOccursMaxOccursBuiltinTypes>Min1_Maz_1_NonNil", Reader.LocalName);
            }
            if (Reader.LocalName=="Min1_Maz_1_Nil") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Min1Maz1Nil = new global::Xtee.Core.Schema.XsdUnsignedShort(Reader.ReadElementString("Min1_Maz_1_Nil")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>XsdMinOccursMaxOccursBuiltinTypes>Min1_Maz_1_Nil", Reader.LocalName);
            }
        }
    }
}
